/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.home.logic;

import com.home.common.LevelSubject;
import com.home.common.utils.HibernateUtil;
import com.home.dao.SubjectDao;
import com.home.mapping.Subject;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import org.hibernate.HibernateException;
import org.hibernate.Session;

/**
 *
 * @author vi
 */
public class SubjectLogic {
    public List<Subject> findAllSubject() {
        return new SubjectDao().findAllSubjects();
    }
    
    public Map<Integer,List<Subject>> findMapAllLevelAndChilds() {
        Map<Integer,List<Subject>> map = new TreeMap<>();
        List<Subject> listData = findAllSubject();
        List<Subject> listLevel1 = new ArrayList<>();
        List<Subject> listLevel2 = new ArrayList<>();
        List<Subject> listLevel3 = new ArrayList<>();
        for (Subject subject : listData) {
            if (subject.getLevel() != null) {
                if (subject.getLevel().compareTo(LevelSubject.SUBJECT_LEVEL_1) == 0) {
                    listLevel1.add(subject);
                } else if (subject.getLevel().compareTo(LevelSubject.SUBJECT_LEVEL_2) == 0) {
                    listLevel2.add(subject);
                } else if (subject.getLevel().compareTo(LevelSubject.SUBJECT_LEVEL_3) == 0) {
                    listLevel3.add(subject);
                }
            }
        }
        map.put(LevelSubject.SUBJECT_LEVEL_1, listLevel1);
        map.put(LevelSubject.SUBJECT_LEVEL_2, listLevel2);
        map.put(LevelSubject.SUBJECT_LEVEL_3, listLevel3);
        return map;
    }
    
     public List<Subject> findByLevel(int Level) {
        return new SubjectDao().findByLevel(Level);
    }
    
}
